help::
	@echo "Available commands"
	@echo "  help           -- (default) print this message"

tests: mypy pytest
help::
	@echo "  tests          -- run all tests for postgrest package"

pytest: start-infra
	uv run --package postgrest pytest --cov=./ --cov-report=xml -vv
help::
	@echo "  pytest         -- run pytest on postgrest package"

mypy:
	uv run --package postgrest mypy src/postgrest tests
help::
	@echo "  mypy           -- run mypy on postgrest package"

start-infra:
	cd infra &&\
	docker compose down &&\
	docker compose up -d
	sleep 2
help::
	@echo "  stop-infra     -- start containers for tests"

stop-infra:
	cd infra &&\
	docker compose down --remove-orphans
help::
	@echo "  stop-infra     -- stop containers for tests"

clean-infra:
	cd infra &&\
	docker compose down --remove-orphans &&\
	docker system prune -a --volumes -f
help::
	@echo "  clean-infra    -- delete all stored information about the containers"

clean:
	rm -rf htmlcov .pytest_cache .mypy_cache .ruff_cache
	rm -f .coverage coverage.xml
help::
	@echo "  clean          -- clean intermediary files generated by tests"

unasync:
	uv run --package postgrest run-unasync.py

build-sync: unasync
	sed -i 's/@pytest.mark.asyncio//g' tests/_sync/test_client.py
	sed -i 's/_async/_sync/g' tests/_sync/test_client.py tests/_sync/test_query_request_builder.py tests/_sync/test_filter_request_builder.py
	sed -i 's/Async/Sync/g' src/postgrest/_sync/request_builder.py tests/_sync/test_client.py
	sed -i 's/_client\.SyncClient/_client\.Client/g' tests/_sync/test_client.py
	sed -i 's/SyncHTTPTransport/HTTPTransport/g' tests/_sync/**.py
	sed -i 's/SyncClient/Client/g' src/postgrest/_sync/**.py tests/_sync/**.py
	sed -i 's/self\.session\.aclose/self\.session\.close/g' src/postgrest/_sync/client.py
help::
	@echo "  build-sync     -- generate _sync from _async implementation"

build:
	uv build --package postgrest
help::
	@echo "  build          -- invoke uv build on postgrest package"
